#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Misc.au3>

_Singleton(@ScriptName, 0)

Dim $folderToRip, $fileSearch, $file, $convertUsingHandbrake, $autoripini, $MakeMKV, $finalMKVNewName, $finalMovieLocation, $iniFile, $handbrakePath
Dim $handbrakeCommandLine, $aRecords, $keepMKV, $MovieLocation, $driveLabel, $i=0
; Define the ini file based on the file version of this script (yes, it includes the .exe but
; this was the simplest way to handle it automatically
$autoripini = @ScriptDir & "\AutoRip2MKV.ini"

; Check to see if the ini file has the correct section.  If not, run the setup
; so that all the correct ini data can be populated.
$iniFile = IniReadSection($autoripini, "AutoRipSettings")

	$tempLocation = $iniFile[2][1]
	$finalMovieLocation = $iniFile[3][1]


If $CmdLine[0] = 2 Then
	$movielocation = $CmdLine[1]
	$driveLabel = $CmdLine[2]


Else
	Exit
EndIf

If StringRight($MovieLocation, 1) = "\" Then
	$MovieLocation = StringTrimRight($MovieLocation, 1)
EndIf
If StringRight($finalMovieLocation, 1) = "\" Then
	$finalMovieLocation = $finalMovieLocation & $driveLabel
Else
	$finalMovieLocation = $finalMovieLocation & "\" & $driveLabel
EndIf

	;$iMsgBoxAnswer = MsgBox(33, "DEBUG!", "param currently = " & $CmdLine[1])

While FileExists ($finalMovieLocation)
	$i = $i + 1
	$finalMovieLocation = $finalMovieLocation & "_" & $i
WEnd

$moveFiles = DirCopy($MovieLocation, $finalMovieLocation, 0)


If $moveFiles = 1 Then
	$i=0
	$moveFiles = DirRemove($MovieLocation, 1)
EndIf

Exit


